#include "HyperbolicFunction.h"
#include "../Helper.h"

using namespace NeuralPlusPlus::Core;

NeuralPlusPlus::Core::LearningRateFunctions::HyperbolicFunction::HyperbolicFunction( double initialLearningRate, double finalLearningRate ) : AbstractFunction(initialLearningRate, finalLearningRate)
	{
	product = initialLearningRate * finalLearningRate;
	}

double NeuralPlusPlus::Core::LearningRateFunctions::HyperbolicFunction::GetLearningRate( int currentIteration, int trainingEpochs )
	{
	Helper::ValidatePositive(trainingEpochs, "trainingEpochs");
	Helper::ValidateWithinRange(currentIteration, 0, trainingEpochs - 1, "currentIteration");

	double denominator = FinalLearningRate
		+ ((InitialLearningRate - FinalLearningRate) * currentIteration) / trainingEpochs;

	if (denominator == 0)
		{
		return 0;
		}
	return product / denominator;
	}